import logging

import requests

mac = '12:23:33:21:c9:33'


def get_ota_version():
    headers = {
        "Device-Id": mac,
        "Content-Type": "application/json"
    }


payload = {
    "flash_size": 16777216,  # 闪存大小 (16MB)
    "minimum_free_heap_size": 8318916,  # 最小可用堆内存
    "mac_address": mac,  # 设备 MAC 地址
    "chip_model_name": "esp32s3",  # 芯片型号
    "chip_info": {
        "model": 9,
        "cores": 2,
        "revision": 2,
        "features": 18
    },
    "application": {
        "name": "xiaozhi",
        "version": "0.9.9"
    },
    "partition_table": [],  # 省略分区表信息
    "ota": {
        "label": "factory"
    },
    "board": {
        "type": "bread-compact-wifi",
        "ip": "192.168.124.38",
        "mac": mac
    }
}
try:
    response = requests.post('https://api.tenclass.net/xiaozhi/ota/', headers=headers, json=payload, timeout=10)
    print(response.json())
    print(response.status_code)
    if response.status_code == 200:
        response_data = response.json()
        logging.info(" OTA 配置更新成功")
    else:
        logging.error(f" OTA 请求失败: {response.status_code}")
except Exception as e:
    logging.error(f" OTA 请求异常: {e}")

get_ota_version()
